﻿using System;
using System.Linq;
using GdHotel.Data.Interfaces;
using UniqueTechnologies.Data.Interfaces;

namespace GdHotel.Data.Repositories
{
    public class AdditionalMenuItemsRepository : IAdditionalMenuItemsRepository
    {
        private GdHotelEntities entities = new GdHotelEntities();

        public IQueryable<AdditionalMenuItem> FindAll()
        {
            return entities.AdditionalMenuItems.AsQueryable();
        }

        public IQueryable<AdditionalMenuItem> FindAllByLang(Language lang)
        {
            return entities.AdditionalMenuItems.Where(mi => mi.LanguageId == lang.Id).AsQueryable();
        }

        public AdditionalMenuItem GetById(Int32 id)
        {
            return entities.AdditionalMenuItems.SingleOrDefault(mi => mi.Id == id);
        }

        public void Insert(AdditionalMenuItem mi)
        {
            entities.AddToAdditionalMenuItems(mi);
        }

        public void Delete(AdditionalMenuItem mi)
        {
            entities.AdditionalMenuItems.DeleteObject(mi);
        }

        public void Save()
        {
            entities.SaveChanges();
        }

        public void Dispose()
        {
            entities.Dispose();
        }
    }
}
